package com.dongdongshop.service.impl.seller_jpa;

import com.dongdongshop.dao.seller_jpa.SellerJpaDao;
import com.dongdongshop.pojo.seller.TbSeller;
import com.dongdongshop.service.seller_jpa.SellerJpaService;
import com.dongdongshop.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class SellerJpaServiceImpl implements SellerJpaService {
    @Autowired
    private SellerJpaDao sellerJpaDao;
    @Override
    public TbSeller getSellerByUsername(String sellerId) {

/*
        TbSeller one = sellerJpaDao.getOne(sellerId);
*/
        TbSeller tbSeller = sellerJpaDao.getSeller(sellerId);
        System.out.println(tbSeller);
        return tbSeller;
    }

    @Override
    @Transactional
    public void register(TbSeller tbSeller) {
        String password = tbSeller.getPassword();
        String salt = ShiroUtils.generateSalt(6);
        String md5Password = ShiroUtils.encryptPassword("MD5", password, salt, 3);
        tbSeller.setPassword(md5Password);
        tbSeller.setSalt(salt);
        sellerJpaDao.save(tbSeller);
    }

    @Override
    public List<TbSeller> listSellerAudit() {
        return sellerJpaDao.getAllByStatusNot("1");
    }

    @Override
    @Transactional
    public void updateSellerStatus(String sellerId, String status) {
        TbSeller tbSeller = new TbSeller();
        tbSeller.setSellerId(sellerId);
        tbSeller.setStatus(status);
        sellerJpaDao.save(tbSeller);
    }
}
